package com.lnking.lnkingplace.mapper;

import com.lnking.lnkingplace.model.dto.place.PlaceCountDto;
import com.lnking.lnkingplace.model.dto.place.PlaceDto;
import com.lnking.lnkingplace.model.dto.place.PlaceExportDto;
import com.lnking.lnkingplace.model.dto.place.PlacePositionDto;
import com.lnking.lnkingplace.model.entity.PlaceInfo;
import com.lnking.lnkingplace.model.request.place.ManagementPlaceListRequest;
import com.lnking.lnkingplace.model.request.place.PlaceListRequest;
import com.lnking.starter.mybatis.mapper.CustomBaseMapper;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * <p>
 * 场所信息表 Mapper 接口
 * </p>
 *
 * @author zhangqt
 * @since 2022-08-18
 */
public interface PlaceInfoMapper extends CustomBaseMapper<PlaceInfo> {

    List<PlaceCountDto> queryStreetCount(String street,String channel);
    List<PlaceCountDto> queryCount(String street,String channel);

    @Select(" SELECT DISTINCT place_type FROM place ")
    List<String> getType();

    @Select(" SELECT DISTINCT street FROM place ")
    List<String> getStreet();

    @Select("select place_type FROM place where del_flag=0 and id = #{placeId}")
    String getPlaceType(String placeId);

    @Select("select place_name FROM place where del_flag=0 and id = #{placeId}")
    String getPlaceName(String placeId);

    @Update(" update place set del_flag = 1 where id = #{id} and process_add_status = #{processAddStatus} ")
    void updateDelFlag(String processAddStatus,String id);

    @Select(" select count(*) FROM place where del_flag = 0 and channel = #{channel} ")
    int queryCountAll(String channel);

    @Select(" select count(*) FROM place where del_flag = 0 and channel = #{channel} and id=#{preciseId}")
    int queryCountByPreciseId(@Param("channel") String channel,@Param("preciseId") String preciseId);

    @Select(" select count(*) FROM place where del_flag = 0 and channel = #{channel} and place_type=#{type}")
    int queryCountByType(@Param("channel") String channel,@Param("type") String type);

    List<PlaceExportDto> queryExportData(PlaceListRequest params);


    @Delete("DELETE FROM place_check_config WHERE place_id = #{placeId}")
    void deletePlaceConfig(String placeId);

    @Insert("INSERT INTO place_check_config(place_id, config_day) VALUE(#{placeId}, #{configDay})")
    void insertPlaceConfig(@Param("placeId") String placeId, @Param("configDay") Integer day);


    PlaceDto getDetail(String id);

    List<String> getTypeByCheckDay(Integer typeCheckDay);

    List<PlacePositionDto> getPosition(String type,String street);

    List<PlaceDto> managementList(ManagementPlaceListRequest params);
}
